#client-build
FROM node:alpine as build-client
ADD ./client /application/client

#ADD ./client /application
#RUN apk add python3
WORKDIR /application/client
RUN npm config set registry http://10.1.10.47:4873 && \
    npm config set @wanhu:registry http://10.1.10.47:5080 && \
    SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/
#RUN npm install node-sass
RUN npm install --save node-sass --registry=https://registry.npm.taobao.org \
                                 --disturl=https://npm.taobao.org/dist \
                                 --sass-binary-site=http://npm.taobao.org/mirrors/node-sass
#RUN npm i node-sass --sass_binary_path=/application/client/linux_musl-x64-83_binding.node
RUN npm install loadsh && npm install
RUN npm run build && rm -rf node_modules

#server-build
FROM node:alpine as build-server
ADD ./server /application/server
RUN npm config set registry http://10.1.10.47:4873 && \
    npm config set @wanhu:registry http://10.1.10.47:5080 && \
    SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/

#RUN npm install node-sass
RUN npm install --save node-sass --registry=https://registry.npm.taobao.org \ 
                                 --disturl=https://npm.taobao.org/dist \ 
                                 --sass-binary-site=http://npm.taobao.org/mirrors/node-sass
#RUN npm i node-sass --sass_binary_path=/application/server/linux_musl-x64-83_binding.node
RUN cd /application/server && npm install loadsh && npm install --production && \
    npm cache clean --force

FROM 10.1.10.47:5000/crm-web-base:7433cf6
COPY --chown=docker-client:docker-client --from=build-client /application/client /application/client
COPY --chown=docker-client:docker-client --from=build-server /application/server /application/server
USER docker-client
WORKDIR /application/server
ENTRYPOINT ["/application/server/node_modules/.bin/egg-framework-wanhu-run", "start"]
